AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Initialize()
	self.Entity:SetModel("models/Items/item_item_crate.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)

	local physics = self.Entity:GetPhysicsObject()
	if (physics:IsValid()) then
		physics:EnableMotion(true)
		physics:Wake()
	end

self.CrateHealth = 20
self.mbox = 1
end

function ENT:RecieveInfo(Original_Object)
	self.CrateHealth = Original_Object.health
end

function ENT:OnTakeDamage(Damage)
	self.CrateHealth = self.CrateHealth - Damage:GetDamage()

	if self.CrateHealth <= 0 then
		self:RemoveIt()
	end
end

function ENT:RemoveIt()
	local pos = self.Entity:GetPos()
	local Choose = math.random(1, 60)

	self:Remove()
	local Random = ents.Create("prop_physics")
	Random:SetModel("models/Items/item_item_crate.mdl")	
	Random:SetPos(pos)
	Random:Spawn()
	Random:Fire("break","",0)
	print(NPCA[Choose])
	local Random2 = ents.Create(NPCA[Choose])
	Random2:SetPos(pos + Vector(0, 0, 50))
	Random2:Spawn()
	--[[print("Skin: " .. tostring(skin))
	print("Model: " .. tostring(model))
	print("Class: " .. tostring(class))
	print("Weapon: " .. tostring(weapon))
	print("Odd: " .. tostring(odd))
	print("|||||||||||||||||||||||||||||||")
	print("")--]]
	--[[if self.NPCCrate == true then
		NPC = ents.Create(NPC)
		if NPCModell != nil then
		NPC:SetModel(NPCModell)
		end
		NPC:SetPos(Pos)
		NPC:Activate()
		NPC:Spawn()
		NPC:SetCollisionGroup(3)
	else
		OriginalProp = ents.Create("prop_physics")
		OriginalProp:SetModel(OriginalModel)
		OriginalProp:SetPos(self:GetPos() + Vector(0, 0, 50))
		OriginalProp:Spawn()
	end--]]
end

function ENT:Use(activator,caller)
	--[[if Crate_Info.CrateShow then
		Crate_Info.CrateShow = false
	else
		Crate_Info.CrateShow = true
	end--]]
end

function ENT:Think()
end

NPCA = {}
NPCA[1] = "npc_alyx"
NPCA[2] = "npc_antlion"
NPCA[3] = "npc_antlionguard"
NPCA[4] = "npc_barnacle"
NPCA[5] = "npc_barney"
NPCA[6] = "npc_breen"
NPCA[7] = "npc_citizen"
NPCA[9] = "npc_combine_s"
NPCA[10] = "npc_combinedropship"
NPCA[11] = "npc_combinegunship"
NPCA[12] = "npc_crow"
NPCA[13] = "npc_cscanner"
NPCA[14] = "npc_dog"
NPCA[15] = "npc_eli"
NPCA[16] = "npc_fastzombie"
NPCA[17] = "npc_gman"
NPCA[18] = "npc_headcrab"
NPCA[19] = "npc_headcrab_black"
NPCA[20] = "npc_headcrab_fast"
NPCA[21] = "npc_helicopter"
NPCA[22] = "npc_kleiner"
NPCA[23] = "npc_manhack"
NPCA[24] = "npc_metropolice"
NPCA[25] = "npc_monk"
NPCA[26] = "npc_mossman"
NPCA[27] = "npc_pigeon"
NPCA[28] = "npc_poisonzombie"
NPCA[29] = "npc_rollermine"
NPCA[30] = "npc_seagull"
NPCA[31] = "npc_sniper"
NPCA[32] = "npc_stalker"
NPCA[33] = "npc_strider"
NPCA[35] = "npc_turret_floor"
NPCA[36] = "npc_turret_ground"
NPCA[37] = "npc_vortigaunt"
NPCA[38] = "npc_zombie"
NPCA[39] = "npc_zombie_torso"
NPCA[40] = "sent_ball"
NPCA[41] = "weapon_striderbuster"
NPCA[42] = "weapon_357"
NPCA[43] = "weapon_alyxgun"
NPCA[45] = "weapon_ar2"
NPCA[47] = "weapon_bugbait"
NPCA[48] = "weapon_citizenpackage"
NPCA[49] = "weapon_citizensuitcase"
NPCA[50] = "weapon_crossbow"
NPCA[51] = "weapon_crowbar"
NPCA[52] = "weapon_extinguisher"
NPCA[53] = "weapon_frag"
NPCA[54] = "weapon_physcannon"
NPCA[55] = "weapon_physgun"
NPCA[56] = "weapon_pistol"
NPCA[57] = "weapon_rpg"
NPCA[58] = "weapon_shotgun"
NPCA[59] = "weapon_smg1"
NPCA[60] = "weapon_stunstick"